package pub.developers.forum.app.manager;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestBody;
import pub.developers.forum.api.model.PageRequestModel;
import pub.developers.forum.api.model.PageResponseModel;
import pub.developers.forum.api.request.AdminBooleanRequest;
import pub.developers.forum.api.request.article.*;
import pub.developers.forum.api.response.article.*;
import pub.developers.forum.api.response.comment.CommentPageResponse;
import pub.developers.forum.api.response.inform.InformPageResponse;
import pub.developers.forum.api.response.user.UserInfoResponse;
import pub.developers.forum.app.support.IsLogin;
import pub.developers.forum.app.support.LoginUserContext;
import pub.developers.forum.app.support.PageUtil;
import pub.developers.forum.app.support.Pair;
import pub.developers.forum.app.transfer.ArticleTransfer;
import pub.developers.forum.app.transfer.UserTransfer;
import pub.developers.forum.common.enums.*;
import pub.developers.forum.common.model.PageResult;
import pub.developers.forum.common.support.CheckUtil;
import pub.developers.forum.common.support.EventBus;
import pub.developers.forum.domain.entity.*;
import pub.developers.forum.domain.entity.value.PostsPageQueryValue;
import pub.developers.forum.domain.repository.*;

import javax.annotation.Resource;
import java.util.*;


@Slf4j
@Component
public class ArticleManager extends AbstractPostsManager {

    @Resource
    private ArticleTypeRepository articleTypeRepository;

    @Resource
    private ArticleRepository articleRepository;

    @Resource
    private UserRepository userRepository;

    @Resource
    private UserFollowRepository userFollowRepository;

    @Resource
    private InformRepository informRepository;



    private static final Long INIT_SORT = 1000L;

    @IsLogin(role = UserRoleEn.ADMIN)
    public void reportReview(AdminBooleanRequest request){
        List<Inform> informs = null;
        String type = request.getType();
        //判断需要被处理的是帖子还是评论还是用户
        informs = informRepository.get(request.getId() , type);
        if (informs.isEmpty())
        {
            return;
        }
        Date update = new Date();
        //处理举报表中多人举报同一个内容的情况
        for (Inform inform : informs)
        {
            inform.setIsDispose(1); //无论审核通过与否 , 该条审核记录都算作被出来了
            // 如果举报成功 审核不通过 false
            if (!request.getIs()){

                User user = LoginUserContext.getUser();
                inform.setAdminerId(user.getId());
                inform.setUpdateAt(update);
                //在帖子表或者评论表只需要单独处理即可 审核不通过要取删除帖子
                if (Objects.equals(request.getType(), "POSTS"))
                {
                    //帖子
                    postsRepository.softDelete(informs.get(0).getInformed(),update);
                }
                else if (Objects.equals(request.getType(), "COMMENTS"))
                {
                    //审核的如果是评论 对应帖子的评论数据需要减一
                    //根据评论id , 拿到帖子id
                    Comment comment = commentRepository.get(informs.get(0).getInformed());
                    //帖子评论数减一
                    postsRepository.decreaseComments(comment.getPostsId() , new Date());
                    commentRepository.softDelete(informs.get(0).getInformed(),update);
                }
                else
                {
                    // 审核的是用户，用户数据变回默认值
                    User u = userRepository.get(informs.get(0).getInformed());
                    // 随机生成昵称
                    // 定义字母表
                    String alphabet = "abcdefghijklmnopqrstuvwxyz";

                    // 创建 Random 对象
                    Random random = new Random();

                    // 生成长度在8到12之间的随机数
                    int length = random.nextInt(5) + 8;

                    // 生成随机字母字符串
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < length; i++) {
                        int index = random.nextInt(alphabet.length());
                        char randomChar = alphabet.charAt(index);
                        sb.append(randomChar);
                    }

                    u.setNickname(sb.toString());
                    u.setAvatar("");
                    u.setAddress("");
                    u.setSignature("");
                    u.setBirthday(null);
                    u.setSex(UserSexEn.UNKNOWN);
                    userRepository.update(u);
                }
            }
            informRepository.save(inform);
        }
    }

    @IsLogin
    @Transactional
    public Long saveArticle(ArticleSaveArticleRequest request) throws Exception {
        // 创建
        if (ObjectUtils.isEmpty(request.getId())) {
            // 校验类型
            // ArticleType articleType = checkArticleType(request.getTypeId());

            // 校验标签
            Set<Tag> selectTags = checkTags(request.getTagIds());

            Article article = ArticleTransfer.toArticle(request, selectTags, false, INIT_SORT);
            articleRepository.save(article);

            // 触发文章创建事件
            EventBus.emit(EventBus.Topic.ARTICLE_CREATE, article);

            return article.getId();
        }

        // 更新
        // 校验文章
        Article article = articleRepository.get(request.getId());
        CheckUtil.isEmpty(article, ErrorCodeEn.ARTICLE_NOT_EXIST);
        CheckUtil.isFalse(LoginUserContext.getUser().getId().equals(article.getAuthor().getId()), ErrorCodeEn.ARTICLE_NOT_EXIST);

        // 校验类型
         ArticleType articleType = checkArticleType(request.getTypeId());

        // 校验标签
        Set<Tag> selectTags = checkTags(request.getTagIds());

        // 删除旧标签关联关系
        tagRepository.deletePostsMapping(request.getId());

        Article oldArticle = article.copy();
        Article newArticle = ArticleTransfer.toArticle(request, articleType, selectTags, true, INIT_SORT);

        articleRepository.update(newArticle);

        // 触发文章更新事件
        EventBus.emit(EventBus.Topic.ARTICLE_UPDATE, Pair.build(oldArticle, newArticle));

        return request.getId();
    }


    @IsLogin
    public FilterArticlePageResponse queryFilterPosts(PageRequestModel pageRequestModel) throws Exception {
       Long[] ids = postsRepository.getFilterPosts( pageRequestModel);
       Long total = postsRepository.getFilterTotal(pageRequestModel); //总数
       List<ArticleInfoResponse> res = new ArrayList<>();
       for (Long id:ids){
           ArticleInfoResponse article = infoFilter(id);
           res.add(article);
       }
       FilterArticlePageResponse filterArticlePageResponse = new FilterArticlePageResponse();
       filterArticlePageResponse.setArticleInfoResponses(res);
       filterArticlePageResponse.setTotal(total);
       return filterArticlePageResponse;
    }

    public PageResponseModel<InformPageResponse> queryReported(PageRequestModel pageRequestModel){
        List<InformPageResponse> res = new ArrayList<>();
        PageResult<Inform> informs = informRepository.getInforms(pageRequestModel);
        for (Inform inform : informs.getList()){
            InformPageResponse informPageResponse = new InformPageResponse();
            // 帖子
            if (inform.getType().equals("POSTS")){
                try {
                    ArticleInfoResponse article = infoFilter(inform.getInformed());
                    informPageResponse.setId(article.getId());
                    informPageResponse.setHeadImg(article.getHeadImg());
                    informPageResponse.setMarkdownContent(article.getMarkdownContent());
                    informPageResponse.setHtmlContent(article.getHtmlContent());
                    informPageResponse.setImages(article.getImages());
                    informPageResponse.setType("POSTS");
                    informPageResponse.setAuthorId(article.getAuthorId());
                    informPageResponse.setAuthorAvatar(article.getAuthorAvatar());
                    informPageResponse.setAuthorNickname(article.getAuthorNickname());
                    informPageResponse.setCreateAt(article.getCreateAt());
                    informPageResponse.setApprovals(article.getApprovals());
                    informPageResponse.setViews(article.getViews());
                    informPageResponse.setComments(article.getComments());
                }catch (Exception e){
                    continue;
                }
            }else if (inform.getType().equals("COMMENTS")){

                CommentPageResponse commentPageResponse = new CommentPageResponse();
                Comment comment = commentRepository.get(inform.getInformed());
                if(comment == null){
                    continue;
                }
                informPageResponse.setType("COMMENTS");
                informPageResponse.setContent(comment.getContent());
                informPageResponse.setId(comment.getId());
                informPageResponse.setCreateAt(comment.getCreateAt());
                User user =  userRepository.get(comment.getUserId());
                if(user == null){
                    continue;
                }
                informPageResponse.setAuthorId(user.getId());
                informPageResponse.setAuthorAvatar(user.getAvatar());
                informPageResponse.setAuthorNickname(user.getNickname());
            }else if (inform.getType().equals("USERS")){
                User user = userRepository.get(inform.getInformed());
                informPageResponse.setType("USERS");
                informPageResponse.setId(user.getId());
                informPageResponse.setAuthorNickname(user.getNickname());
                informPageResponse.setAuthorAvatar(user.getAvatar());

            }
            informPageResponse.setInformer(UserTransfer.toUserInfoResponse(userRepository.get(inform.getInformer())));

            res.add(informPageResponse);
        }
        return PageResponseModel.build(informs.getTotal() , informs.getSize() , res);
    }

    public List<ArticleInfoResponse> queryBan(PageRequestModel pageRequestModel){
        List<ArticleInfoResponse> res = new ArrayList<>();
        Long[]postIds = postsRepository.getBanPostsId(pageRequestModel);
        for (Long postId : postIds){
            ArticleInfoResponse article = new ArticleInfoResponse();
            try {
                article = infoBan(postId);
            } catch (Exception e) {
               continue;
            }
            res.add(article);
        }
        return res;
    }

    public List<ArticleQueryTypesResponse> queryAllTypes() {
        List<ArticleType> articleTypes = articleTypeRepository.queryByState(AuditStateEn.PASS);

        return ArticleTransfer.toArticleQueryTypesResponses(articleTypes);
    }

    @IsLogin(role = UserRoleEn.ADMIN)
    public List<ArticleQueryTypesResponse> queryAdminTypes() {
        List<ArticleType> articleTypes = articleTypeRepository.queryByState(null);

        return ArticleTransfer.toArticleQueryTypesResponses(articleTypes);
    }

    @IsLogin(role = UserRoleEn.ADMIN)
    public PageResponseModel<ArticleQueryTypesResponse> typePage(PageRequestModel<ArticleAdminTypePageRequest> pageRequestModel) {
        ArticleAdminTypePageRequest typePageRequest = pageRequestModel.getFilter();
        ArticleType articleType = ArticleType.builder()
                .name(typePageRequest.getName())
                .description(typePageRequest.getDescription())
                .build();
        if (!ObjectUtils.isEmpty(typePageRequest.getAuditState())) {
            articleType.setAuditState(AuditStateEn.getEntity(typePageRequest.getAuditState()));
        }
        if (!ObjectUtils.isEmpty(typePageRequest.getScope())) {
            articleType.setScope(ArticleTypeScopeEn.getEntity(typePageRequest.getScope()));
        }
        PageResult<ArticleType> pageResult = articleTypeRepository.page(PageUtil.buildPageRequest(pageRequestModel, articleType));

        return PageResponseModel.build(pageResult.getTotal(), pageResult.getSize(), ArticleTransfer.toArticleQueryTypesResponses(pageResult.getList()));
    }

    @IsLogin
    public List<ArticleQueryTypesResponse> queryEditArticleTypes() {
        List<ArticleTypeScopeEn> scopes = new ArrayList<>();
        scopes.add(ArticleTypeScopeEn.USER);

        User loginUser = LoginUserContext.getUser();
        if (!UserRoleEn.USER.equals(loginUser.getRole() )) {
            scopes.add(ArticleTypeScopeEn.OFFICIAL);
        }

        List<ArticleType> articleTypes = articleTypeRepository.queryByScopesAndState(scopes, AuditStateEn.PASS);

        return ArticleTransfer.toArticleQueryTypesResponses(articleTypes);
    }

    @IsLogin(role = UserRoleEn.ADMIN)
    public void addType(ArticleAddTypeRequest request) {
        CheckUtil.isNotEmpty(articleTypeRepository.query(ArticleType.builder()
                .name(request.getName())
                .build()), ErrorCodeEn.ARTICLE_TYPE_IS_EXIST);

        articleTypeRepository.save(ArticleTransfer.toArticleType(request));
    }

    public PageResponseModel<ArticleUserPageResponse> userPage(PageRequestModel<ArticleUserPageRequest> pageRequestModel) {
        PostsPageQueryValue pageQueryValue = PostsPageQueryValue.builder()
                .auditStates(Arrays.asList(AuditStateEn.PASS.getValue()))
                .build();

        ArticleUserPageRequest pageRequest = pageRequestModel.getFilter();
        if (!ObjectUtils.isEmpty(pageRequest.getTypeName())) {
            ArticleType articleType = articleTypeRepository.getByNameAndState(pageRequest.getTypeName(), AuditStateEn.PASS);
            CheckUtil.isEmpty(articleType, ErrorCodeEn.ARTICLE_TYPE_IS_EXIST);

            pageQueryValue.setTypeId(articleType.getId());
        }

        return pageQuery(pageRequestModel, pageQueryValue);
    }

    public PageResponseModel<ArticleUserPageResponse> authorPage(PageRequestModel<ArticleAuthorPageRequest> pageRequestModel) {
        ArticleAuthorPageRequest request = pageRequestModel.getFilter();

        List<String> auditStates = new ArrayList<>();
        auditStates.add(AuditStateEn.PASS.getValue());

        User user = LoginUserContext.getUser();
        if (!ObjectUtils.isEmpty(user) && user.getId().equals(request.getUserId())) {
            auditStates.add(AuditStateEn.WAIT.getValue());
            auditStates.add(AuditStateEn.REJECT.getValue());
        }

        PostsPageQueryValue pageQueryValue = PostsPageQueryValue.builder()
                .auditStates(auditStates)
                .authorId(request.getUserId())
                .build();

        return pageQuery(pageRequestModel, pageQueryValue);
    }

    @IsLogin(role = UserRoleEn.ADMIN)
    public PageResponseModel<ArticleUserPageResponse> adminPage(PageRequestModel<ArticleAdminPageRequest> pageRequestModel) {

        ArticleAdminPageRequest request = pageRequestModel.getFilter();

        PostsPageQueryValue pageQueryValue = PostsPageQueryValue.builder()
                .category(PostsCategoryEn.ARTICLE.getValue())
                .authorId(request.getUserId())
                .typeId(request.getTypeId())
                .title(request.getTitle())
                .official(request.getOfficial())
                .marrow(request.getMarrow())
                .top(request.getTop())
                .build();
        if (!ObjectUtils.isEmpty(request.getAuditState()) && !ObjectUtils.isEmpty(AuditStateEn.getEntity(request.getAuditState()))) {
            List<String> auditStates = new ArrayList<>();
            auditStates.add(AuditStateEn.getEntity(request.getAuditState()).getValue());
            pageQueryValue.setAuditStates(auditStates);
        }
        return pageQuery(pageRequestModel, pageQueryValue);
    }

    @IsLogin(role = UserRoleEn.ADMIN)
    public void adminTop(AdminBooleanRequest booleanRequest) {
        BasePosts basePosts = postsRepository.get(booleanRequest.getId());
        CheckUtil.isEmpty(basePosts, ErrorCodeEn.ARTICLE_NOT_EXIST);

        basePosts.setSort(booleanRequest.getIs() ? 1L : INIT_SORT);
        basePosts.setTop(booleanRequest.getIs());
        postsRepository.update(basePosts);
    }

    @IsLogin(role = UserRoleEn.ADMIN)
    public void adminOfficial(AdminBooleanRequest booleanRequest) {
        BasePosts basePosts = postsRepository.get(booleanRequest.getId());
        CheckUtil.isEmpty(basePosts, ErrorCodeEn.ARTICLE_NOT_EXIST);

        basePosts.setOfficial(booleanRequest.getIs());
        postsRepository.update(basePosts);
    }

    @IsLogin(role = UserRoleEn.ADMIN)
    public void adminMarrow(AdminBooleanRequest booleanRequest) {
        BasePosts basePosts = postsRepository.get(booleanRequest.getId());
        CheckUtil.isEmpty(basePosts, ErrorCodeEn.ARTICLE_NOT_EXIST);

        basePosts.setMarrow(booleanRequest.getIs());
        postsRepository.update(basePosts);
    }

    @IsLogin(role = UserRoleEn.ADMIN)
    public void typeAuditState(AdminBooleanRequest booleanRequest) {
        ArticleType articleType = articleTypeRepository.get(booleanRequest.getId());
        CheckUtil.isEmpty(articleType, ErrorCodeEn.ARTICLE_TYPE_IS_EXIST);

        articleType.setAuditState(booleanRequest.getIs() ? AuditStateEn.PASS : AuditStateEn.REJECT);
        articleTypeRepository.update(articleType);
    }


    //管理员删除文章
    @IsLogin(role = UserRoleEn.ADMIN)
    public void deleteArticle(ArticleDeleteRequest articleDeleteRequest) {
        int[] ids = articleDeleteRequest.getIds();
        articleTypeRepository.deleteArticle(ids);
    }

    public ArticleInfoResponse info(Long id) throws Exception {
        Article article = articleRepository.get(id);
        CheckUtil.isEmpty(article, ErrorCodeEn.ARTICLE_NOT_EXIST);

        if (!AuditStateEn.PASS.equals(article.getAuditState())) {
            User user = LoginUserContext.getUser();
            CheckUtil.isEmpty(user, ErrorCodeEn.ARTICLE_IN_AUDIT_PROCESS);
            CheckUtil.isFalse(user.getId().equals(article.getAuthor().getId()), ErrorCodeEn.ARTICLE_IN_AUDIT_PROCESS);
        }

        // 触发文章查看详情事件
        EventBus.emit(EventBus.Topic.POSTS_INFO, article);

        return ArticleTransfer.toArticleInfoResponse(article);
    }

    public ArticleInfoResponse infoFilter(Long id) throws Exception {
        Article article = articleRepository.get(id);
        CheckUtil.isEmpty(article, ErrorCodeEn.ARTICLE_NOT_EXIST);

        // 触发文章查看详情事件
        EventBus.emit(EventBus.Topic.POSTS_INFO, article);

        return ArticleTransfer.toArticleInfoResponse(article);
    }

    public ArticleInfoResponse infoBan(Long id) throws Exception {
        Article article = articleRepository.get(id);
        CheckUtil.isEmpty(article, ErrorCodeEn.ARTICLE_NOT_EXIST);

        if (!AuditStateEn.PASS.equals(article.getAuditState())) {
            User user = LoginUserContext.getUser();
        }

        // 触发文章查看详情事件
        EventBus.emit(EventBus.Topic.POSTS_INFO, article);

        return ArticleTransfer.toArticleInfoResponse(article);
    }

    private PageResponseModel<ArticleUserPageResponse> pageQuery(PageRequestModel pageRequestModel, PostsPageQueryValue pageQueryValue) {
        pageQueryValue.setCategory(PostsCategoryEn.ARTICLE.getValue());


        PageResult<Article> pageResult = articleRepository.page(pageRequestModel.getPageNo(), pageRequestModel.getPageSize(), pageQueryValue);

        return PageResponseModel.build(pageResult.getTotal(), pageResult.getSize(), ArticleTransfer.toArticleUserPageResponses(pageResult.getList()));
    }

    private ArticleType checkArticleType(Long typeId) {
        ArticleType articleType = articleTypeRepository.get(typeId);
        CheckUtil.isEmpty(articleType, ErrorCodeEn.ARTICLE_TYPE_IS_EXIST);
        CheckUtil.isFalse(AuditStateEn.PASS.equals(articleType.getAuditState()), ErrorCodeEn.ARTICLE_TYPE_IS_EXIST);

        return articleType;
    }

    //用户查看自己发表的帖子
    @IsLogin
    public List<ArticleInfoResponse> querySelfPostsManager(PageRequestModel pageRequestModel,Long userId) throws Exception {
        List<ArticleInfoResponse> result = new ArrayList<>();
        //需要拿到当前登录用户的id
        User user = new User();
        if (userId == null || userId == 0){
            user = LoginUserContext.getUser();
        }else {
            user = userRepository.get(userId);
        }
        //根据用户id拿到用户发表的帖子id
        Long[] postIds = postsRepository.getPostsId(user.getId(), pageRequestModel);
        //循环遍历帖子id 拿到每一篇帖子的详细信息
        for (Long postId : postIds)
        {
            ArticleInfoResponse article = new ArticleInfoResponse();
            article = info(postId);

            // 粉丝数
            Long id = article.getAuthorId();
            List<UserInfoResponse> users = userRepository.selectSelfFollower(id);
            article.setFans(users != null ? (long) users.size(): 0);

            // 是否点赞
            Long foodId = userFollowRepository.getLike(LoginUserContext.getUser().getId(),postId);
            article.setLike(foodId != null ? true:false);

            result.add(article);
        }
        return result;
    }

    // 获取所有帖子
    @IsLogin
    public List<ArticleInfoResponse> queryAllPosts(@RequestBody PageRequestModel pageRequestModel) throws Exception {
        List<ArticleInfoResponse> res = new ArrayList<>();
        Long[]postIds = postsRepository.getPostsId(pageRequestModel);
        User user = LoginUserContext.getUser();
        for (Long postId : postIds){
            ArticleInfoResponse article = new ArticleInfoResponse();
            try {
                article = info(postId);
            }catch (Exception e){
                continue;
            }


            Long id = article.getAuthorId();
            List<UserInfoResponse> users = userRepository.selectSelfFollower(id);
            // 粉丝数
            article.setFans(users != null ? (long) users.size(): 0);

            // 是否点赞
            Long foodId = userFollowRepository.getLike(user.getId(),postId);
            article.setLike(foodId != null ? true:false);

            // 是否关注
            Follow follow = userRepository.getFollow(article.getAuthorId(),user.getId());
            article.setFollow(follow != null ? true: false);

            res.add(article);
        }

        return res;
    }

    //获取当前登录用户点赞的帖子
    @IsLogin
    public PageResponseModel<ArticleLoveResponse> queryMyLovePosts(Integer pageNo , Integer pageSize) throws Exception {
        List<ArticleLoveResponse> result = new ArrayList<>();
        //获取当前登录用户的id
        User user = LoginUserContext.getUser();
        Long id = user.getId();
        //获取我点过赞的帖子的id
        PageResult<Long> myLovePostsId = userRepository.queryMyLoveId(id , pageNo , pageSize);

        ////System.out.println(Arrays.toString(myLovePostsId));
        //根据帖子id拿到帖子信息
        for(Long postId : myLovePostsId.getList())
        {
            Article article = articleRepository.get(postId);
            if (article != null)
            {
                // 触发文章查看详情事件
                EventBus.emit(EventBus.Topic.POSTS_INFO, article);
                ArticleInfoResponse articleInfoResponse = ArticleTransfer.toArticleInfoResponse(article);
                Long authorId = articleInfoResponse.getAuthorId();//作者id
                List<UserInfoResponse> users = userRepository.selectSelfFollower(authorId);
                //查询粉丝数目
                articleInfoResponse.setFans(users != null ? (long) users.size():0);
                //是否点赞
                Long foodId = userFollowRepository.getLike(user.getId() , postId);
                articleInfoResponse.setLike(foodId != null);
                //是否关注
                Follow follow = userRepository.getFollow(articleInfoResponse.getAuthorId() , user.getId());
                articleInfoResponse.setFollow(follow != null);
                result.add(ArticleTransfer.toArticleResponse(articleInfoResponse));
            }
        }
        return PageResponseModel.build(myLovePostsId.getTotal() , myLovePostsId.getSize(), result);
    }

    //用户举报帖子或者评论
    @IsLogin
    public void  addInform(ArticleInformRequest articleInformRequest)
    {
        //如果被举报的是帖子 检查被举报的帖子是否还存在
        if (articleInformRequest.getType().equals("POSTS")){
            Article article = articleRepository.get(articleInformRequest.getInformed());
            CheckUtil.isEmpty(article, ErrorCodeEn.ARTICLE_NOT_EXIST);
        }
        else if (articleInformRequest.getType().equals("COMMENTS"))
        {
            //检查评论是否存在
            Comment reply = commentRepository.get(articleInformRequest.getInformed());
            CheckUtil.isEmpty(reply, ErrorCodeEn.COMMENT_NOT_EXIST);
        }else {
            if (articleInformRequest.getInformed() == LoginUserContext.getUser().getId()){
                return;
            }
            // 检查用户是否存在
            User user = userRepository.get(articleInformRequest.getInformed());
            CheckUtil.isEmpty(user,ErrorCodeEn.USER_NOT_EXIST);

        }
        //获取当前登录的用户的id
        Long id = LoginUserContext.getUser().getId();
        articleRepository.insertInform(articleInformRequest,id);
    }

    //查询官方帖子
    @IsLogin
    public List<ArticleUserPageResponse> queryOfficial()
    {
        List<Article> articles = articleRepository.official();
        return ArticleTransfer.toArticleUserPageResponses(articles);
    }
}
